package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Dynamic;
import cn.wolfcode.trip.base.domain.Strategy;
import cn.wolfcode.trip.base.mapper.DynamicMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IDynamicService;
import cn.wolfcode.trip.base.util.UserContext;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class DynamicServiceImpl implements IDynamicService {

    @Autowired
    private DynamicMapper dynamicMapper;

    @Override
    public int deleteByPrimaryKey(Long id) {
        return dynamicMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Dynamic dynamic) {
        //设置完用户再存进动态表中
        dynamic.setUser(UserContext.getCurrentUser());
        return dynamicMapper.insert(dynamic);
    }

    @Override
    public Dynamic selectByPrimaryKey(Long id) {
        return dynamicMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Dynamic> selectAll() {
        return dynamicMapper.selectAll();
    }

    @Override
    public int updateByPrimaryKey(Dynamic record) {
        return dynamicMapper.updateByPrimaryKey(record);
    }
    public PageInfo query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        List<Dynamic> list = dynamicMapper.selectForList(qo);
        return new PageInfo(list);
    }
}
